package com.ilab.service.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

import com.ilab.model.Employee;
import com.ilab.service.EmployeeService;

// 这里配置@Transactional用处是让spring的事务管理器接管该service的事务.
@Transactional
public class EmployeeServiceImpl extends BasicAbstractService implements EmployeeService {
	


	public Employee checkEmployee(Employee employee) {
		
		String hql = "from Employee where id=? and pwd=?";
//		System.out.println(sessionFactory.getCurrentSession().createQuery(hql).setString(0, employee.getId() + "").setString(1, employee.getPwd() + "").list());
//		List<Employee> list = sessionFactory.getCurrentSession().createQuery(hql).setString(0, employee.getId() + "").setString(1, employee.getPwd() + "").list();
	
		Object[] parameters = {employee.getId(), employee.getPwd()};
		
		List list = this.executeQuery(hql, parameters);
		
		if(list.size() == 0)
		{
			return null;
		}else {
			return (Employee) list.get(0);
		}

	}
	
	// 显示所有雇员
	public List showEmployeeList(int pageSize, int pageNow) {
		String hql = "from Employee order by id";
		return this.executeQueryByPage(hql, null, pageNow, pageSize);
	}

	// 获取总页数
	public int getPageCount(int pageSize) {
		String hql = "select count(*) from Employee";

		return this.queryPageCount(hql, null, pageSize);
	}
}
